package com.yc.jpyy.facecheck.controller;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.config.Config;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.TeacherDao;
import com.yc.jpyy.mobile.service.TeacherService;

@Controller
@RequestMapping(value = "/facecheck")
public class CoachFaceCheckController extends BaseController{
	@Autowired
	private TeacherService teacherService;
	
	private static Logger logger = LoggerFactory.getLogger(CoachFaceCheckController.class);	
	
	@Autowired
	private TeacherDao teacherDao;
	
	/**
	 *通过身份证号获取教练基本信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/GetTeacherInfo", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	public @ResponseBody String GetTeacherInfo(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			// 身份证编号
			String IdCardNum = request.getParameter("IdCardNum");
			if(IdCardNum != null && !IdCardNum.isEmpty()){
				String imgUrl = Config.getImageAddress();
				Map<String, Object> valMap = new HashMap<String, Object>();
				valMap.put("imgUrl", imgUrl);
				valMap.put("IdCardNum", IdCardNum);
				List<Map<String, Object>> stumap = teacherService.getTeacherInfo(valMap);
				if (stumap != null && stumap.size() > 0) {
					response.setData(stumap);
				}else {
					response.setErrorcode(1);
					response.setMessage("教练无基本信息...");
				}
			}else{
				response.setErrorcode(1);
				response.setMessage("身份证号不能为空...");
			}		
		} catch (Exception e) {
			logger.info("GetTeacherInfo:"+ e.toString());
			response.setReturnMsg(1,"教练基本信息获取失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	/**
	 *通过教练全国编号获取教练基本信息（通过扫二维码登陆以后调此接口获取信息）
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/GetTeacherInfoByNum", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	public @ResponseBody String GetTeacherInfoByNum(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			// 身份证编号
			String Coachnum = request.getParameter("Coachnum");
			if(Coachnum != null && !Coachnum.isEmpty()){
				String imgUrl = Config.getImageAddress();
				Map<String, Object> valMap = new HashMap<String, Object>();
				valMap.put("imgUrl", imgUrl);
				valMap.put("Coachnum", Coachnum);
				List<Map<String, Object>> stumap = teacherService.getTeacherInfo(valMap);
				if (stumap != null && stumap.size() > 0) {
					response.setData(stumap);
				}else {
					response.setErrorcode(1);
					response.setMessage("该教练无基本信息...");
				}
			}else{
				response.setErrorcode(1);
				response.setMessage("教练全国编号不能为空...");
			}	
		} catch (Exception e) {
			logger.info("GetTeacherInfoByNum:"+ e.toString());
			response.setReturnMsg(1,"教练基本信息获取失败！");
		} finally {
			return response.toJSON();
		}
	}

	
	
}
